def differential_manchester_decode(signal):
    """
    解码差分曼彻斯特编码的信号。

    :param signal: 字符串，表示差分曼彻斯特编码的信号，每个字符为 'H' 或 'L'
    :return: 字符串，表示解码后的二进制数据
    """
    if len(signal) % 2 != 0:
        raise ValueError("信号长度必须是偶数")

    decoded_bits = []
    previous_bit = None

    for i in range(0, len(signal), 2):
        first_half = signal[i]
        second_half = signal[i + 1]

        if first_half == second_half:
            current_bit = '1'
        else:
            current_bit = '0'

        if previous_bit is None:
            previous_bit = current_bit
        else:
            if current_bit == '1':
                previous_bit = '1' if previous_bit == '0' else '0'
            decoded_bits.append(previous_bit)

    return ''.join(decoded_bits)

def main():
    # 示例信号，假设 'H' 表示高电平，'L' 表示低电平
    signal = "HLHHLLHHLLHHLLHH"

    try:
        decoded_data = differential_manchester_decode(signal)
        print(f"解码后的二进制数据: {decoded_data}")
    except ValueError as e:
        print(f"错误: {e}")

if __name__ == "__main__":
    main()
